# -*- python -*-
# Author: Charles Wang <charlesw123456@gmail.com>
# License: GPLv2.
import os.path

import SCons.Builder
import SCons.Node.FS
import SCons.Util

env = Environment()
csccom = "$CSC $CSCFLAGS -out:${TARGET.abspath} $SOURCES"
csclibcom = "$CSC -t:library $CSCLIBFLAGS $_CSCLIBPATH $_CSCLIBS -out:${TARGET.abspath} $SOURCES"

McsBuilder = SCons.Builder.Builder(action = '$CSCCOM',
                                   source_factory = SCons.Node.FS.default_fs.Entry,
                                   suffix = '.exe')
McsLibBuilder = SCons.Builder.Builder(action = '$CSCLIBCOM',
                                      source_factory = SCons.Node.FS.default_fs.Entry,
                                      suffix = '.dll')
env['BUILDERS']['CLIProgram'] = McsBuilder
env['BUILDERS']['CLILibrary'] = McsLibBuilder

env['CSC'] = 'gmcs'
env['_CSCLIBS'] = "${_stripixes('-r:', CILLIBS, '', '-r', '', __env__)}"
env['_CSCLIBPATH'] = "${_stripixes('-lib:', CILLIBPATH, '', '-r', '', __env__)}"
env['CSCFLAGS'] = SCons.Util.CLVar('')
env['CSCCOM'] = SCons.Action.Action(csccom)
env['CSCLIBCOM'] = SCons.Action.Action(csclibcom)

Export('env')

SConscript(os.path.join('coco', 'SConscript'))

Import('CocoExe')

CocoXmlExe = env.CLIProgram('cocoxml', ['CocoXml.cs', 'Scanner.cs', 'Tab.cs',
                                        'XSData.cs', 'ParserGen.cs',
                                        'Parser.cs'])
env.Command(['Scanner.cs', 'Parser.cs'], [CocoExe, 'CocoXml.atg'],
            'mono $SOURCES -namespace at.jku.ssw.CocoXml')
Export('CocoXmlExe')

XmlScannerFrame = env.File('XmlScanner.frame')
XmlParserFrame = env.File('XmlParser.frame')

Export('XmlScannerFrame', 'XmlParserFrame')
SConscript(os.path.join('samples', 'SConscript'))
